package com.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学习使用全文索引
 *
 * @author 夏智峰
 * @create 2018-03-05 14:11
 */
@RestController
@RequestMapping("/full")
public class SpringDateFullTextIndexController {
//  @Autowired
//  private ArticleSearchRepository articleSearchRepository;
//
//  /**
//   * @desc 向索引中插入文档
//   * @author 夏智峰
//   * @create 2018/3/5 14:13
//   **/
//  @RequestMapping("/add")
//  public void testSaveArticleIndex() {
//    Article article = new Article();
//    article.setId(1L);
//    article.setTitle("springboot integreate elasticsearch");
//    article.setAbstracts("springboot integreate elasticsearch is very easy");
//    article.setContent("elasticsearch based on lucene,"
//            + "spring-data-elastichsearch based on elaticsearch"
//            + ",this tutorial tell you how to integrete springboot with spring-data-elasticsearch");
//    article.setPostTime(new Date());
//    article.setClickCount(1L);
//    articleSearchRepository.save(article);
//
//    Article article1 = new Article();
//    article1.setId(2L);
//    article1.setTitle("springboot 书籍");
//    article1.setAbstracts("springboot的书");
//    article1.setContent("elasticsearch based on lucene");
//    article1.setPostTime(new Date());
//    article1.setClickCount(1L);
//
//    articleSearchRepository.save(article1);
//  }
//
//  /**
//   * @desc 根据文档id删除指定文档
//   * @author 夏智峰
//   * @create 2018/3/5 14:14
//   **/
//  @RequestMapping("/del/{id}")
//  public void delById(@PathVariable(value = "id") Long id) {
//    articleSearchRepository.delete(id);
//  }
//
//  /**
//   * @desc 使用单字符段匹配测试
//   * @author 夏智峰
//   * @create 2018/3/5 14:18
//   **/
//  @RequestMapping("/querybytitle/{title}")
//  public List<Article> testSearchByTitle(@PathVariable(value = "title") String title) {
//    Iterable<Article> searchResult = articleSearchRepository.findByTitle(title);
//    return result(searchResult.iterator());
//  }
//
//
//  /**
//   * @desc 全文索引
//   * @author 夏智峰
//   * @create 2018/3/5 14:15
//   **/
//  @RequestMapping("/query/{queryString}")
//  public List<Article> testSearch(@PathVariable(value = "queryString") String queryString) {
//    QueryStringQueryBuilder builder = new QueryStringQueryBuilder(queryString);
//    Iterable<Article> searchResult = articleSearchRepository.search(builder);
//    return result(searchResult.iterator());
//  }
//
//  /**
//   * @desc 输出结果
//   * @author 夏智峰
//   * @create 2018/3/5 14:25
//  **/
//  public List<Article> result(Iterator<Article> iterator) {
//    List<Article> list = new ArrayList<>();
//    Article article;
//    while (iterator.hasNext()) {
//      article = iterator.next();
//      System.out.println(article);
//      list.add(article);
//    }
//    return list;
//  }
}
